using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using Rss;

namespace LWRSSReader
{
	public class ChannelsTypeConverter : TypeConverter
	{


		public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
		{
			if (sourceType == typeof(string))
			{
				return true;
			}

			return base.CanConvertFrom(context, sourceType);
		}
		public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
		{

			if (value is string)
			{
				try
				{
					return ((RssFeedWrap)context.Instance)[(string)value];
				}
				catch (Exception ex)
				{
					throw ex;
				}
				
			}
			return base.ConvertFrom(context, culture, value);
		}

		public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
		{
			if (destinationType == typeof(System.String) && value is RssChannel)
			{

				return ((RssChannel)value).Title;
			}

			return base.ConvertTo(context, culture, value, destinationType);
		}

		public override bool CanConvertTo(ITypeDescriptorContext context,System.Type destinationType)
		{
			if (destinationType == typeof(RssChannel))
				return true;

			return base.CanConvertTo(context, destinationType);
		}

		public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
		{
			return true;
		}
		public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
		{
			return true;
		}
		public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
		{
			RssFeedWrap ff = ((RssFeedWrap)context.Instance);
			return new StandardValuesCollection(ff.Channels);
		}

	}
}
